package com.base.library.view.systemPhotoAlbum;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.base.library.R;
import com.base.library.fragment.BaseFragment;
import com.base.library.view.zoomImageView.ZoomImageView;

/**
 * 作者：王东一 on 2016/5/31 13:03
 **/
public class PhotoInfoFragment extends BaseFragment {
    private boolean isBuild = false;
    private ZoomImageView zoom_imageView;
    private String url;
    private Point mPoint = new Point(0, 0);//用来封装ImageView的宽和高的对象
    public PhotoInfoFragment(Context mContext, String url) {
        this.url = url;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setContentView(inflater, R.layout.photo_info_fragment);
        if (!isViewShown && !isBuild) {
            lazyLoad();
        }
        return main;
    }

    @Override
    protected void init() {
        zoom_imageView = (ZoomImageView) main.findViewById(R.id.zoom_imageView);
        //利用NativeImageLoader类加载本地图片
        Bitmap bitmap = NativeImageLoader.getInstance().loadNativeImage(url, mPoint, new NativeImageLoader.NativeImageCallBack() {

            @Override
            public void onImageLoader(Bitmap bitmap, String path) {
                if (bitmap != null && zoom_imageView != null) {
                    zoom_imageView.setImageBitmap(bitmap);
                }
            }
        });
    }

    @Override
    protected void lazyLoad() {
        isBuild = true;
        init();
    }
}
